package com.sgam.mf.domain.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.springframework.format.annotation.DateTimeFormat;

import com.sgam.mf.domain.ref.RefBank;
import com.sgam.mf.domain.ref.RefBranch;
import com.sgam.mf.domain.ref.RefCompany;
import com.sgam.mf.domain.ref.RefDomains;
import com.sgam.mf.domain.ref.RefGift;
import com.sgam.mf.domain.ref.RefServices;
import com.sgam.mf.domain.ref.RefStatus;
import com.sgam.mf.domain.sec.SecUser;
import com.sgam.mf.helper.RomanianNumberToWords;
import com.sgam.utils.CustomDateDeserializer;
import com.sgam.utils.CustomDateSerializer;
import com.sgam.utils.CustomDateTimeSerializer;

@Entity
@Table(name = "CONTRACTS")
public class Contracts implements Comparable<Contracts> {


	@Id
	@Column(name = "id")
	@GeneratedValue
	private Integer id;
	
	@Column(name = "contract_no", nullable = true) 
	private String contractNo;
	
	@ManyToOne
	@JoinColumn(name = "ref_company_fk") 
	private RefCompany refCompany;
	
	@ManyToOne
	@JoinColumn(name = "ref_branch_fk") 
	private RefBranch refBranch;
	
	@ManyToOne
	@JoinColumn(name = "ref_services_fk") 
	private RefServices refServices;

	@ManyToOne
	@JoinColumn(name = "ref_domains_fk") 
	private RefDomains refDomains;
	
	@Column(name = "person_flg") 
	private Integer personFlg;
	
	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "application_pers_fiz_fk") 
	private ApplicationPersFiz applicationPersFiz;
	
	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "application_pers_jur_fk") 
	private ApplicationPersJur applicationPersJur;
	
	@ManyToOne
	@JoinColumn(name = "ref_status_fk") 
	private RefStatus refStatus;
	
	@ManyToOne
	@JoinColumn(name = "respons_consultant_fk") 
	private SecUser responsConsultant;
	
	@ManyToOne
	@JoinColumn(name = "respons_personal_fk") 
	private SecUser responsPersonal;
	
	@ManyToOne
	@JoinColumn(name = "respons_personal2_fk") 
	private SecUser responsPersonal2;
	
	@Column(name = "consultant_comment") 
	private String consultantComment;
	
//	@Column(name = "personal_comment") 
//	private String personalComment;
	
	@Column(name = "black_list_flg") 
	private Integer blackListFlg;
	
	@Column(name = "amount") 
	private Integer amount;
	
	@Column(name = "prepayment") 
	private Integer prepayment;
	
	@Column(name = "contractat_flg") 
	private Integer contractatFlg;
	
	@Column(name = "finalizat_flg") 
	private Integer finalizatFlg;
	
	@Column(name = "updated_by_fk", nullable = true) 
	private Integer updatedByFk;
	
	@JsonSerialize(using = CustomDateTimeSerializer.class)
	@DateTimeFormat(pattern="dd.MM.yyyy HH:mm")
	@Column(name = "updated_date", nullable = true) 
	private Date updatedDate;
	
	@ManyToOne
	@JoinColumn(name = "ref_gift_fk") 
	private RefGift refGift;
	
	@Column(name = "pers_fiz_name") 
	private String persFizName;
	
	@Column(name = "pers_jur_name") 
	private String persJurName;
	
	@JsonSerialize(using = CustomDateSerializer.class)
	@JsonDeserialize(using = CustomDateDeserializer.class)
	@DateTimeFormat(pattern="dd.MM.yyyy")
	@Column(name = "contract_date") 
	private Date contractDate;
	
	@Column(name = "suma") 
	private Integer suma;
	
	@Column(name = "destinatia") 
	private String destinatia;
	
	@Column(name = "consultatia") 
	private Integer consultatia;
	
	@Column(name = "intermediere") 
	private Integer intermediere;
	
//	
//	@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=true)
//	@Fetch(value = FetchMode.SUBSELECT)
//	@JoinColumn(name="contract_id_fk")
//	@OrderBy("refActivityType.id")
//	private List<ApplicationActivityType> applicationActivityType;
	
	@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=true)
	@Fetch(value = FetchMode.SUBSELECT)
	@JoinColumn(name="contract_id_fk")
	@OrderBy("refPropertyType.id")
	private List<ApplicationPropertyType> applicationPropertyType = new ArrayList<ApplicationPropertyType>();
	
//	@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=true)
//	@Fetch(value = FetchMode.SUBSELECT)
//	@JoinColumn(name="contract_id_fk")
//	private List<ApplicationFiles> applicationFiles = new ArrayList<ApplicationFiles>();
	
	
	@ManyToOne
	@JoinColumn(name = "reg_persons_fk") 
	private RegPersons regPersons;
	
	@ManyToOne
	@JoinColumn(name = "reg_companies_fk") 
	private RegCompanies regCompanies;
	
	@Column(name = "chat") 
	private String chat;
	
	@Column(name = "de_monitorizat") 
	private Integer deMonitorizat;
	
	@Column(name = "dosar_complet") 
	private Integer dosarComplet;
	
	@Column(name = "dosar_transmis") 
	private Integer dosarTransmis;
	
	@Column(name = "dosar_finantat") 
	private Integer dosarFinantat;
	
	@Column(name = "dosar_refuzat") 
	private Integer dosarRefuzat;
	
	@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=false)
	@Fetch(value = FetchMode.SUBSELECT)
	@JoinColumn(name="contract_id_fk")
	@OrderBy("refProjectType.id")
	private List<ApplicationProjectType> applicationProjectType;
	
	@JsonSerialize(using = CustomDateSerializer.class)
	@JsonDeserialize(using = CustomDateDeserializer.class)
	@DateTimeFormat(pattern="dd.MM.yyyy")
	@Column(name = "app_reg_date") 
	private Date appRegDate;
	
	@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=true)
	@Fetch(value = FetchMode.SUBSELECT)
	@JoinColumn(name="contract_id_fk")
	//@OrderBy("contractAddAgree.id")
	private List<ContractAddAgree> contractAddAgree = new ArrayList<ContractAddAgree>();
	
	@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=true)
	@Fetch(value = FetchMode.SUBSELECT)
	@JoinColumn(name="contract_id_fk")
	private List<ContractPayments> contractPayments = new ArrayList<ContractPayments>();
	
	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "contract_asig_fk") 
	private ContractAsig contractAsig;

	
	@Transient
	private String activityTypeDesc;
	
	@Transient
	private String applPerson;
	
	@Transient
	private String applFiscCode;
	
	@Transient
	private String projTypeDesc;
	
	@Transient
	private String optionsDesc;
	
	@Transient
	private String creditAmount;
	
	@Transient
	private String contractPerson;
	
	@Transient
	private String contractFiscCode;
	
	@Transient
	private Integer dbt;
	
	@Transient
	private String paymentOptionsDesc;
	
	@Transient
	private String amountInWords;
	
	@Transient
	private String percentInWords;
	
	@Transient
	private String amountTotalInWords;
	
	@Transient
	private String prepaymentInWords;
	
	@Transient
	private String dbtInWords;
	
	@Column(name = "marinati") 
	private Integer marinati;
	
	@Column(name = "last_comment_user_fk") 
	private Integer lastCommentUserFk;
	
	@Transient
	private String bunuriInfo;
	
	@ManyToOne
	@JoinColumn(name = "ref_bank_fk") 
	private RefBank refBank;
	
	@Column(name = "constr_obiect") 
	private String constrObiect;
	
	@Column(name = "constr_proiect") 
	private String constrProiect;
	
	@Column(name = "constr_proiect_elaborat") 
	private String constrProiectElaborat;
	
	@Column(name = "constr_autoriz") 
	private String constrAutoriz;
	
	@Column(name = "constr_termen") 
	private String constrTermen;
	
	@Column(name = "constr_benef") 
	private String constrBenef;
	
	@Column(name = "constr_benef_idnp") 
	private String constrBenefIdnp;
	
	@Column(name = "constr_benef_adresa") 
	private String constrBenefAdresa;
	
	@Column(name = "ec_rul1") 
	private Integer ecRul1;
	
	@Column(name = "ec_rul2") 
	private Integer ecRul2;
	
	@Column(name = "ec_rul3") 
	private Integer ecRul3;
	
	@Column(name = "ec_rul4") 
	private Integer ecRul4;
	
	@Column(name = "ec_rul5") 
	private Integer ecRul5;
	
	@Column(name = "ec_rul6") 
	private Integer ecRul6;
	
	@Column(name = "ec_regsub") 
	private Integer ecRegsub;
	
	@Column(name = "ec_addact") 
	private Integer ecAddact;
	
	@Column(name = "ec_regcasa") 
	private Integer ecRegcasa;
	
	@Column(name = "ec_regcont") 
	private Integer ecRegcont;
	
	@Column(name = "ec_cons") 
	private Integer ecCons;
	
	@Column(name = "ec_contr") 
	private Integer ecContr;
	
	@Column(name = "ec_alte") 
	private Integer ecAlte;
	
	@Transient
	private Integer ecTotal;
	
	@Transient
	private String ecTotalInWords;
	
	@Transient
	private String aeFiscDate;
	
	@Transient
	private Integer aeFiscTVAAmount;
	
	@Transient
	private Integer aeFiscAmountWithoutTVA;
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getContractNo() {
		return contractNo;
	}

	public void setContractNo(String contractNo) {
		this.contractNo = contractNo;
	}

	public RefCompany getRefCompany() {
		return refCompany;
	}

	public void setRefCompany(RefCompany refCompany) {
		this.refCompany = refCompany;
	}

	public RefBranch getRefBranch() {
		return refBranch;
	}

	public void setRefBranch(RefBranch refBranch) {
		this.refBranch = refBranch;
	}

	public RefServices getRefServices() {
		return refServices;
	}

	public void setRefServices(RefServices refServices) {
		this.refServices = refServices;
	}

	public RefDomains getRefDomains() {
		return refDomains;
	}

	public void setRefDomains(RefDomains refDomains) {
		this.refDomains = refDomains;
	}

	public Integer getPersonFlg() {
		return personFlg;
	}

	public void setPersonFlg(Integer personFlg) {
		this.personFlg = personFlg;
	}

	public ApplicationPersFiz getApplicationPersFiz() {
		return applicationPersFiz;
	}

	public void setApplicationPersFiz(ApplicationPersFiz applicationPersFiz) {
		this.applicationPersFiz = applicationPersFiz;
	}

	public ApplicationPersJur getApplicationPersJur() {
		return applicationPersJur;
	}

	public void setApplicationPersJur(ApplicationPersJur applicationPersJur) {
		this.applicationPersJur = applicationPersJur;
	}

	public RefStatus getRefStatus() {
		return refStatus;
	}

	public void setRefStatus(RefStatus refStatus) {
		this.refStatus = refStatus;
	}

	public SecUser getResponsConsultant() {
		return responsConsultant;
	}

	public void setResponsConsultant(SecUser responsConsultant) {
		this.responsConsultant = responsConsultant;
	}

	public SecUser getResponsPersonal() {
		return responsPersonal;
	}

	public void setResponsPersonal(SecUser responsPersonal) {
		this.responsPersonal = responsPersonal;
	}
	
	public SecUser getResponsPersonal2() {
		return responsPersonal2;
	}

	public void setResponsPersonal2(SecUser responsPersonal2) {
		this.responsPersonal2 = responsPersonal2;
	}

	public String getConsultantComment() {
		return consultantComment;
	}

	public void setConsultantComment(String consultantComment) {
		this.consultantComment = consultantComment;
	}

//	public String getPersonalComment() {
//		return personalComment;
//	}
//
//	public void setPersonalComment(String personalComment) {
//		this.personalComment = personalComment;
//	}

	public Integer getBlackListFlg() {
		return blackListFlg;
	}

	public void setBlackListFlg(Integer blackListFlg) {
		this.blackListFlg = blackListFlg;
	}

	public Integer getAmount() {
		return amount;
	}

	public void setAmount(Integer amount) {
		this.amount = amount;
	}

	public Integer getPrepayment() {
		return prepayment;
	}

	public void setPrepayment(Integer prepayment) {
		this.prepayment = prepayment;
	}

	public Integer getContractatFlg() {
		return contractatFlg;
	}

	public void setContractatFlg(Integer contractatFlg) {
		this.contractatFlg = contractatFlg;
	}

	public Integer getFinalizatFlg() {
		return finalizatFlg;
	}

	public void setFinalizatFlg(Integer finalizatFlg) {
		this.finalizatFlg = finalizatFlg;
	}

	public Integer getUpdatedByFk() {
		return updatedByFk;
	}

	public void setUpdatedByFk(Integer updatedByFk) {
		this.updatedByFk = updatedByFk;
	}

	public Date getUpdatedDate() {
		return updatedDate;
	}

	public void setUpdatedDate(Date updatedDate) {
		this.updatedDate = updatedDate;
	}

	public RefGift getRefGift() {
		return refGift;
	}

	public void setRefGift(RefGift refGift) {
		this.refGift = refGift;
	}

	public String getPersFizName() {
		return persFizName;
	}

	public void setPersFizName(String persFizName) {
		this.persFizName = persFizName;
	}

	public String getPersJurName() {
		return persJurName;
	}

	public void setPersJurName(String persJurName) {
		this.persJurName = persJurName;
	}

	public Date getContractDate() {
		return contractDate;
	}

	public void setContractDate(Date contractDate) {
		this.contractDate = contractDate;
	}

	public Integer getSuma() {
		return suma;
	}

	public void setSuma(Integer suma) {
		this.suma = suma;
	}

	public String getDestinatia() {
		return destinatia;
	}

	public void setDestinatia(String destinatia) {
		this.destinatia = destinatia;
	}

	public Integer getConsultatia() {
		return consultatia;
	}

	public void setConsultatia(Integer consultatia) {
		this.consultatia = consultatia;
	}

	public Integer getIntermediere() {
		return intermediere;
	}

	public void setIntermediere(Integer intermediere) {
		this.intermediere = intermediere;
	}

	
//	public List<ApplicationActivityType> getApplicationActivityType() {
//		return applicationActivityType;
//	}
//
//	public void setApplicationActivityType(
//			List<ApplicationActivityType> applicationActivityType) {
//		this.applicationActivityType = applicationActivityType;
//	}

	public List<ApplicationPropertyType> getApplicationPropertyType() {
		return applicationPropertyType;
	}

	public void setApplicationPropertyType(
			List<ApplicationPropertyType> applicationPropertyType) {
		this.applicationPropertyType = applicationPropertyType;
	}

	
//	public List<ApplicationFiles> getApplicationFiles() {
//		return applicationFiles;
//	}
//
//	public void setApplicationFiles(List<ApplicationFiles> applicationFiles) {
//		this.applicationFiles = applicationFiles;
//	}

	
	
	public RegPersons getRegPersons() {
		return regPersons;
	}

	public void setRegPersons(RegPersons regPersons) {
		this.regPersons = regPersons;
	}

	public RegCompanies getRegCompanies() {
		return regCompanies;
	}

	public void setRegCompanies(RegCompanies regCompanies) {
		this.regCompanies = regCompanies;
	}

	
	
	public String getChat() {
		return chat;
	}

	public void setChat(String chat) {
		this.chat = chat;
	}

	
	
	public Integer getDeMonitorizat() {
		return deMonitorizat;
	}

	public void setDeMonitorizat(Integer deMonitorizat) {
		this.deMonitorizat = deMonitorizat;
	}

	public Integer getDosarComplet() {
		return dosarComplet;
	}

	public void setDosarComplet(Integer dosarComplet) {
		this.dosarComplet = dosarComplet;
	}

	public Integer getDosarTransmis() {
		return dosarTransmis;
	}

	public void setDosarTransmis(Integer dosarTransmis) {
		this.dosarTransmis = dosarTransmis;
	}

	public Integer getDosarFinantat() {
		return dosarFinantat;
	}

	public void setDosarFinantat(Integer dosarFinantat) {
		this.dosarFinantat = dosarFinantat;
	}

	public Integer getDosarRefuzat() {
		return dosarRefuzat;
	}

	public void setDosarRefuzat(Integer dosarRefuzat) {
		this.dosarRefuzat = dosarRefuzat;
	}

	
	
	public List<ApplicationProjectType> getApplicationProjectType() {
		return applicationProjectType;
	}

	public void setApplicationProjectType(
			List<ApplicationProjectType> applicationProjectType) {
		this.applicationProjectType = applicationProjectType;
	}

	
	
	public Date getAppRegDate() {
		return appRegDate;
	}

	public void setAppRegDate(Date appRegDate) {
		this.appRegDate = appRegDate;
	}

	
	
	
	
	public List<ContractAddAgree> getContractAddAgree() {
		return contractAddAgree;
	}

	public void setContractAddAgree(List<ContractAddAgree> contractAddAgree) {
		this.contractAddAgree = contractAddAgree;
	}

	public String getActivityTypeDesc() {
		try {
			if (getPersonFlg()==1){
				return getApplicationPersFiz().getRefActivityType().getMdValue();
			}
			else {
				return getApplicationPersJur().getRefActivityType().getMdValue();
			}
		}
		catch (Exception e)  {
			return "";
		}
	}
	
	
	public String getApplPerson() {
		try {
			if (getPersonFlg()==1){
				return getApplicationPersFiz().getRegPersons().getFirstName()+" "+getApplicationPersFiz().getRegPersons().getLastName();
			}
			else {
				return getApplicationPersJur().getRegCompanies().getCompanyName();
			}
		}
		catch (Exception e)  {
			return "";
		}	
	}

	
	public String getApplFiscCode() {
		try {
			if (getPersonFlg()==1){
				return getApplicationPersFiz().getRegPersons().getIdnp();
			}
			else {
				return getApplicationPersJur().getRegCompanies().getIdno();
			}
		}
		catch (Exception e)  {
			return "";
		}	
	}
		
	

	public String getProjTypeDesc() {
		try {
			String vString="";
			for (int i = 0; i < getApplicationProjectType().size(); i++) {
				if (getApplicationProjectType().get(i).getValue()==1) {
				vString=vString+getApplicationProjectType().get(i).getRefProjectType().getMdValue()+", ";
				}
			}
			return vString;
		}
		catch (Exception e)  {
			return "";
		}
	}
	
	
	public String getOptionsDesc() {
		try {
			String vString="";
			
			if (getDeMonitorizat()==1) {vString=vString+"De monitorizat, ";}
			if (getDosarComplet() ==1) {vString=vString+" Dosar comlet, ";}
			if (getDosarTransmis()==1) {vString=vString+" Dosar transmis, ";}
			if (getDosarFinantat()==1) {vString=vString+" Dosar finalizat, ";}
			if (getDosarRefuzat() ==1) {vString=vString+" Dosar refuzat, " ;}
			if (getBlackListFlg() ==1) {vString=vString+" In lista neagra";}
			
			return vString;
		}
		catch (Exception e)  {
			return "";
		}
	}

	public String getCreditAmount() {
		try {
			if (getPersonFlg()==1){
				return getApplicationPersFiz().getCreditAmount();
			}
			else {
				return getApplicationPersJur().getCreditAmount();
			}
		}
		catch (Exception e)  {
			return "";
		}	
	}

	public String getContractPerson() {
		try {
			if (getPersonFlg()==1){
				return getRegPersons().getFirstName()+" "+getRegPersons().getLastName();
			}
			else {
				return getRegCompanies().getCompanyName();
			}
		}
		catch (Exception e)  {
			return "";
		}	
	}

	
	public String getContractFiscCode() {
		try {
			if (getPersonFlg()==1){
				return getRegPersons().getIdnp();
			}
			else {
				return getRegCompanies().getIdno();
			}
		}
		catch (Exception e)  {
			return "";
		}	
	}
	
	
	
	public Integer getDbt() {
		try {
			return getAmount()-getPrepayment();
		}
		catch (Exception e)  {
			return null;
		}
	}

	public String getPaymentOptionsDesc() {
		try {
			String vString="";
			
			if (getContractatFlg()==1) {vString=vString+"Contractat";} else {vString=vString+"Necontractat";} 
//			if (getFinalizatFlg()==1) {vString=vString+" Finalizat";}
			
			return vString;
		}
		catch (Exception e)  {
			return "";
		}
	}
	
	
	
	public String getAmountInWords() {
		try {
			return "("+RomanianNumberToWords.convert(getConsultatia())+")"; //amountInWords;
		}
		catch (Exception e)  {
			return "";
		}
	}

	public String getPercentInWords() {
		try {
			return "("+RomanianNumberToWords.convert(getIntermediere())+")"; //percentInWords;
		}
		catch (Exception e)  {
			return "";
		}
	}
	
	public String getAmountTotalInWords() {
		try {
			return "("+RomanianNumberToWords.convert(getAmount())+")"; //amountInWords;
		}
		catch (Exception e)  {
			return "";
		}
	}

	public String getPrepaymentInWords() {
		try {
			return "("+RomanianNumberToWords.convert(getPrepayment())+")"; //prepaymentInWords;
		}
		catch (Exception e)  {
			return "";
		}
	}
	
	public String getDbtInWords() {
		try {
			return "("+RomanianNumberToWords.convert(getDbt())+")"; //dbtInWords;
		}
		catch (Exception e)  {
			return "";
		}
	}
	

	public Integer getMarinati() {
		return marinati;
	}

	public void setMarinati(Integer marinati) {
		this.marinati = marinati;
	}
	
	

	public Integer getLastCommentUserFk() {
		return lastCommentUserFk;
	}

	public void setLastCommentUserFk(Integer lastCommentUserFk) {
		this.lastCommentUserFk = lastCommentUserFk;
	}


	public RefBank getRefBank() {
		return refBank;
	}

	public void setRefBank(RefBank refBank) {
		this.refBank = refBank;
	}

	

	public String getBunuriInfo() {
		try {
			String vString="";
			for (int i = 0; i < getContractAddAgree().size(); i++) {
				vString=vString+getContractAddAgree().get(i).getCompany();
				if (getContractAddAgree().get(i).getAmount().toString().length()!=0){
					vString=vString+", nr. "+getContractAddAgree().get(i).getAmount().toString();
				}
				if (getContractAddAgree().get(i).getGoods().length()!=0){
					vString=vString+", "+getContractAddAgree().get(i).getGoods();
				}
				vString=vString+";  ";
				
			}
			return vString.substring(0,vString.length()-3);
		}
		catch (Exception e)  {
			return "";
		}
	}
	
	
	
	public List<ContractPayments> getContractPayments() {
		return contractPayments;
	}

	public void setContractPayments(List<ContractPayments> contractPayments) {
		this.contractPayments = contractPayments;
	}
	
	


	public ContractAsig getContractAsig() {
		return contractAsig;
	}

	public void setContractAsig(ContractAsig contractAsig) {
		this.contractAsig = contractAsig;
	}

	public String getConstrObiect() {
		return constrObiect;
	}

	public void setConstrObiect(String constrObiect) {
		this.constrObiect = constrObiect;
	}

	public String getConstrProiect() {
		return constrProiect;
	}

	public void setConstrProiect(String constrProiect) {
		this.constrProiect = constrProiect;
	}

	public String getConstrProiectElaborat() {
		return constrProiectElaborat;
	}

	public void setConstrProiectElaborat(String constrProiectElaborat) {
		this.constrProiectElaborat = constrProiectElaborat;
	}

	public String getConstrAutoriz() {
		return constrAutoriz;
	}

	public void setConstrAutoriz(String constrAutoriz) {
		this.constrAutoriz = constrAutoriz;
	}

	public String getConstrTermen() {
		return constrTermen;
	}

	public void setConstrTermen(String constrTermen) {
		this.constrTermen = constrTermen;
	}

		
	public String getConstrBenef() {
		return constrBenef;
	}

	public void setConstrBenef(String constrBenef) {
		this.constrBenef = constrBenef;
	}

	public String getConstrBenefIdnp() {
		return constrBenefIdnp;
	}

	public void setConstrBenefIdnp(String constrBenefIdnp) {
		this.constrBenefIdnp = constrBenefIdnp;
	}

	public String getConstrBenefAdresa() {
		return constrBenefAdresa;
	}

	public void setConstrBenefAdresa(String constrBenefAdresa) {
		this.constrBenefAdresa = constrBenefAdresa;
	}

	
	
	public Integer getEcRul1() {
		return ecRul1;
	}

	public void setEcRul1(Integer ecRul1) {
		this.ecRul1 = ecRul1;
	}

	public Integer getEcRul2() {
		return ecRul2;
	}

	public void setEcRul2(Integer ecRul2) {
		this.ecRul2 = ecRul2;
	}

	public Integer getEcRul3() {
		return ecRul3;
	}

	public void setEcRul3(Integer ecRul3) {
		this.ecRul3 = ecRul3;
	}

	public Integer getEcRul4() {
		return ecRul4;
	}

	public void setEcRul4(Integer ecRul4) {
		this.ecRul4 = ecRul4;
	}

	public Integer getEcRul5() {
		return ecRul5;
	}

	public void setEcRul5(Integer ecRul5) {
		this.ecRul5 = ecRul5;
	}

	public Integer getEcRul6() {
		return ecRul6;
	}

	public void setEcRul6(Integer ecRul6) {
		this.ecRul6 = ecRul6;
	}

	public Integer getEcRegsub() {
		return ecRegsub;
	}

	public void setEcRegsub(Integer ecRegsub) {
		this.ecRegsub = ecRegsub;
	}

	public Integer getEcAddact() {
		return ecAddact;
	}

	public void setEcAddact(Integer ecAddact) {
		this.ecAddact = ecAddact;
	}

	public Integer getEcRegcasa() {
		return ecRegcasa;
	}

	public void setEcRegcasa(Integer ecRegcasa) {
		this.ecRegcasa = ecRegcasa;
	}

	public Integer getEcRegcont() {
		return ecRegcont;
	}

	public void setEcRegcont(Integer ecRegcont) {
		this.ecRegcont = ecRegcont;
	}

	public Integer getEcCons() {
		return ecCons;
	}

	public void setEcCons(Integer ecCons) {
		this.ecCons = ecCons;
	}

	public Integer getEcContr() {
		return ecContr;
	}

	public void setEcContr(Integer ecContr) {
		this.ecContr = ecContr;
	}

	public Integer getEcAlte() {
		return ecAlte;
	}

	public void setEcAlte(Integer ecAlte) {
		this.ecAlte = ecAlte;
	}
	
	public Integer getEcTotal() {
		Integer amt=0;
		if (getEcRul1()!=null){
			amt+=getEcRul1();
		}
		if (getEcRul2()!=null){
			amt+=getEcRul2();
		}
		if (getEcRul3()!=null){
			amt+=getEcRul3();
		}
		if (getEcRul4()!=null){
			amt+=getEcRul4();
		}
		if (getEcRul5()!=null){
			amt+=getEcRul5();
		}
		if (getEcRul6()!=null){
			amt+=getEcRul6();
		}
		
		if (getEcAddact()!=null){
			amt+=getEcAddact();
		}
		if (getEcAlte()!=null){
			amt+=getEcAlte();
		}
		if (getEcCons()!=null){
			amt+=getEcCons();
		}
		if (getEcContr()!=null){
			amt+=getEcContr();
		}
		if (getEcRegcasa()!=null){
			amt+=getEcRegcasa();
		}
		if (getEcRegcont()!=null){
			amt+=getEcRegcont();
		}
		if (getEcRegsub()!=null){
			amt+=getEcRegsub();
		}
		return amt;
	}
	
	public String getEcTotalInWords() {
		try {
			return "("+RomanianNumberToWords.convert(+getEcTotal())+")"; //amountInWords;
		}
		catch (Exception e)  {
			return "";
		}
	}
	
	

	public String getAeFiscDate() {
		String ret="";
		if (getRegCompanies().getCompanyName()!=null){
			ret=getRegCompanies().getCompanyName();
		}
		if (getRegCompanies().getJuridicAddress()!=null) {
			ret=ret+", "+getRegCompanies().getJuridicAddress();
		}
		if (getRegCompanies().getBankAccount()!=null) {
			ret=ret+", c/d: "+getRegCompanies().getBankAccount();		
				}
		if (getRegCompanies().getRefBank()!=null) {
			ret=ret+", "+getRegCompanies().getRefBank().getMdValue();
		}
		if (getRegCompanies().getBankCode()!=null) {
			ret=ret+", c/b: "+getRegCompanies().getBankCode();
		}
		return ret;
	}
	
	public Integer getAeFiscTVAAmount() {
		return getAmount()/5;
	}

	public Integer getAeFiscAmountWithoutTVA() {
		return getAmount()-getAmount()/5;
	}

	@Override
	public int compareTo(Contracts c) {
        if (c.getId() > this.id) return -1;
        if (c.getId() == this.id) return 0;
        return 1;
    }
	
}


 

